<template>
  <!--  页面跳转,表格数据也需要跳转-->
  <div  style="width:80%">
    <div style="margin-bottom: 30px">编辑管理员</div>
    <el-form :inline="true" :model="form" label-width="100px">
      <el-form-item label="用户名" prop="username">
        <el-input v-model="form.username" placeholder="请输入用户名"></el-input>
      </el-form-item>

      <el-form-item label="联系方式" prop="phone">
        <el-input v-model="form.phone" placeholder="请输入联系方式"></el-input>
      </el-form-item>
      <el-form-item label="邮箱">
        <el-input v-model="form.email" placeholder="请输入邮箱"></el-input>
      </el-form-item>
    </el-form>

    <div style="text-align:center;margin-top:30px">
      <el-button type="primary" @click="save" size="medium">提交</el-button>
      <!--      <el-button type="danger">返回列表</el-button>-->
    </div>
  </div>
</template>

<script>
import request from "@/utils/request";
export default {
  name: "EditAdmin",
  data(){
    return{
      form:{}
    }
  },
  created(){
    const id=this.$route.query.id
    //这个方法 将后台通过id查出来的user对象赋给form
    request.get("/admin/"+ id).then(res => {
      this.form = res.data
    })
  },
  methods: {
    save(){
      //  save方法用于提交数据
      request.put('/admin/update',this.form).then(res => {
        if (res.code === '200'){
          this.$notify.success('更新成功')
          //  新增成功后清空输入框内数据
          this.$router.push("/adminList")
        } else{
          this.$notify.error(res.msg)
        }

      })
    }
  }
}
</script>

<style scoped>

</style>